package com.league.zjxn.main.access

import androidx.core.widget.addTextChangedListener
import com.league.zjxn.R
import com.league.zjxn.jetpack.vmodel.AccessViewModel
import com.module.lemlin.owner.OwnerAbstractFragment
import com.module.lemlin.owner.OwnerViewModeFragment
import kotlinx.android.synthetic.main.fragment_access_login_pass.*

class LoginPassFragment : OwnerViewModeFragment<AccessViewModel>() {

    companion object {
        fun newInstance(): LoginPassFragment {
            return LoginPassFragment()
        }
    }

    override fun viewModel(): AccessViewModel {
        return createViewModel(requireActivity())
    }

    override val layoutResId: Int
        get() = R.layout.fragment_access_login_pass

    override fun initView() {
        etLoginPassPhone.addTextChangedListener { editable ->
            editable?.let { viewModel.mMapLoginPass["mobile"] = it.toString() }
            tvLoginPassSubmit.isEnabled =
                !editable.isNullOrEmpty() && !etLoginPassPwd.text.isNullOrEmpty()
        }
        etLoginPassPwd.addTextChangedListener { editable ->
            editable?.let { viewModel.mMapLoginPass["password"] = it.toString() }
            tvLoginPassSubmit.isEnabled =
                !editable.isNullOrEmpty() && !etLoginPassPhone.text.isNullOrEmpty()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        viewModel.mMapLoginPass.clear()
    }
}